import { defineStore } from 'pinia'

export const useUserStore = defineStore({
  id: 'user', // id必填，且需要唯一
  state: () => {
    return {
      token: '',
      adminAccount: '18826226470',
      userInfo: {
        user_id: '',
        user_name: '',
        phone_num: ''
      }
    }
  },
  actions: {
    /** 设置全局token
     * @param {String} token token
     */
    setToken(token) {
      this.token = token || ''
    },

    /** 设置用户信息
     * @param {*} info
     */
    setUserInfo(info) {
      this.userInfo.user_id = info?.user_id || ''
      this.userInfo.user_name = info?.user_name || ''
      this.userInfo.phone_num = info?.phone_num || ''
    }
  },
  persist: {
    storage: sessionStorage,
    paths: ['token', 'userInfo']
  }
})
